package com.property.cleaning.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.property.cleaning.entity.User;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

/**
 * 用户Mapper接口
 * 
 * @author Property Cleaning System
 */
@Mapper
public interface UserMapper extends BaseMapper<User> {

    /**
     * 根据用户名查询用户
     */
    @Select("SELECT u.*, r.role_name FROM users u " +
            "LEFT JOIN roles r ON u.role_id = r.id " +
            "WHERE u.username = #{username} AND u.status = 1")
    User findByUsername(@Param("username") String username);

    /**
     * 根据邮箱查询用户
     */
    @Select("SELECT u.*, r.role_name FROM users u " +
            "LEFT JOIN roles r ON u.role_id = r.id " +
            "WHERE u.email = #{email} AND u.status = 1")
    User findByEmail(@Param("email") String email);

    /**
     * 根据手机号查询用户
     */
    @Select("SELECT u.*, r.role_name FROM users u " +
            "LEFT JOIN roles r ON u.role_id = r.id " +
            "WHERE u.phone = #{phone} AND u.status = 1")
    User findByPhone(@Param("phone") String phone);
}